#include "stdlib.h"
#include "kstd.h"
#include "gdt.h"

void* sbrk(ssize_t increment)
{
  t_segment_descriptor* user_data = gdt_get_user_data();

  t_uint8* old_brk = 0;

  /* old_brk += user_data->base_addr; */
  /* old_brk += user_data->base << 16; */
  /* old_brk += user_data->base2 << 24; */

  old_brk += user_data->seg_limit;
  old_brk += user_data->limit << 16;

  t_uint8* new_brk = old_brk + increment;

  user_data->seg_limit = (t_uint32) new_brk;
  user_data->limit = (t_uint32) new_brk >> 16;

  return old_brk;
}

void*   malloc(size_t size)
{
  void* old_brk = sbrk(size);

  return old_brk;
}

void    free(void* ptr)
{
  return;
}
